home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 11 / develop 11 code / The NetWork Project / Examples (Sources) / hello.p < prev    next >
Encoding:
Text File  |  1992-07-15  |  3.0 KB  |  126 lines  |  [TEXT/MPS ]

  1. program Hello;
  2. {     Copyright 1990 The NetWork Project, StatLab Heidelberg.   }
  3.  
  4. uses     MemTypes, QuickDraw, OSIntf, ToolIntf, SysEqu;
  5.  
  6.     PROCEDURE InitToolBox;
  7.     const callsToMoreMasters=10;
  8.         VAR
  9.             i : integer;
  10.             p : GrafPtr;
  11.             m : MenuHandle;
  12.             applZone:        THz;
  13.             oldMoreMast:    INTEGER;
  14.     
  15.     BEGIN
  16.         MaxApplZone;
  17.         
  18.     { Here is a trick - Stolen from MacApp- sugested by Jerome C. }
  19.         applZone := ApplicZone;
  20.         oldMoreMast := applZone^.moreMast;
  21.         applZone^.moreMast := oldMoreMast * callsToMoreMasters;
  22.         MoreMasters;
  23.         applZone^.moreMast := oldMoreMast;
  24.  
  25.         InitGraf(@thePort);                {initialize QuickDraw}
  26.         InitFonts;                           {initialize Font Manager}
  27.         InitWindows;                       {initialize Window Manager}
  28.         InitMenus;                           {initialize Menu Manager}
  29.         TEInit;                            {initialize TextEdit}
  30.         InitDialogs(NIL);                   {initialize Dialog Manager}
  31.         InitCursor;                        {call QuickDraw to make cursor (pointer) an arrow}
  32.  
  33.         m := GetMenu (1);
  34.         AddResMenu (m, 'DRVR');
  35.         InsertMenu (m, 0);
  36.         m := GetMenu (2); InsertMenu (m, 0);
  37.     END;
  38.  
  39. type RgnHPtr = ^RgnHandle; IntPtr = ^integer;
  40.  
  41. var savedgrayrgn, newgrayrgn, mousergn : RgnHandle; 
  42.     w : WindowPtr; pw : integer; ev : EventRecord;
  43.     mousepos : Point;
  44.     theDialog:DialogPtr;
  45.  
  46. PROCEDURE CenterRect(VAR GlobR : rect;vh:vhselect);
  47.     {Center a rectangle to center of screen}
  48. VAR    xdel, ydel,screenWidth,screenHeight: integer;
  49. BEGIN
  50.     with screenbits do 
  51.     begin 
  52.         screenwidth := bounds.right - bounds.left;
  53.         screenHeight := bounds.bottom - bounds.top;
  54.     end;
  55.     xdel:=0;ydel:=0;
  56.     WITH GlobR DO
  57.         if vh=h then xdel := ((screenWidth - (right - left)) DIV 2) - left
  58.         else ydel := ((screenHeight - (bottom - top)) DIV 2) - top;
  59.     offsetRect(GlobR, xdel, ydel);
  60. END;
  61.  
  62. PROCEDURE CenterWindow(wptr:windowptr;vh:vhselect);
  63.     {Center a window to center of screen}
  64. CONST
  65.     MakeFront = False;
  66. VAR
  67.     r, rbound : rect;
  68. BEGIN
  69.     if Wptr<>nil then begin
  70.         r := wptr^.portRect;
  71.         rbound := wptr^.portbits.bounds;
  72.         OffsetRect(r, -rbound.left, -rbound.top);
  73.         CenterRect(R,vh);
  74.         MoveWindow(wptr, r.left, r.top, MakeFront);
  75.     end;
  76. END;
  77.  
  78.  
  79. var tempAlert : AlertTHndl;
  80.     i:integer;
  81.     stoptime:longint;
  82. BEGIN
  83.     InitToolBox;
  84.     drawmenubar;
  85.  
  86.     theDialog := GetNewDialog(130,NIL,Pointer(-1));
  87.     IF theDialog=NIL THEN
  88.     BEGIN {Fatal:could not process dialog}
  89.         sysbeep(2);
  90.     END
  91.     ELSE BEGIN
  92.  
  93.         CenterWindow(theDialog,h);
  94.         showwindow(theDialog);
  95.         selectwindow(theDialog);
  96.         setport(thedialog);
  97.         invalrect(thedialog^.portrect);
  98.         Beginupdate(theDialog);
  99.         drawdialog(theDialog);Endupdate(theDialog);
  100.     END;
  101.  
  102.     stoptime:=tickcount+60*10;
  103.  
  104.     REPEAT
  105.  
  106.         IF WaitNextEvent (EveryEvent, ev, 60, mousergn) THEN 
  107.         CASE ev.what OF
  108.             activateEvt: stoptime:=tickcount+60*10;    {reset the stop time}
  109.  
  110.             updateEvt : BEGIN
  111.  
  112.                 IF isDialogEvent(ev) THEN
  113.                 UpdtDialog(Dialogptr(ev.Message),thePort^.visRgn);
  114.                 stoptime:=tickcount+60*10;    {reset the stop time}
  115.  
  116.             END;
  117.             diskEvt : IF Point (ev.message).v <> noErr THEN
  118.             IF Eject (NIL, Point (ev.message).h) <> noErr THEN;
  119.             {     Eject bad disks . }
  120.         END;
  121.  
  122.     UNTIL (ev.what IN [keydown..autoKey, mousedown, diskEvt, app4Evt]) 
  123.     OR (tickcount>stoptime);
  124.  
  125. END.
  126.